<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>	
<%@ include file="/pub/headmeta.jsp" %>
</head>
<body style="background-color: #f5fafd">
	<div class="right-head"><span class="right-head-font">商品分类管理</span></div>
	
	<table id="MyTableList" width="100%">
		<tr align="center">
			<td width="30%" style="background-color: #f5fafd" valign="top" align="left">
				<ul id="tree"  style="background-color: #f5fafd; font-size: 12px;" class="easyui-tree" animate="true"></ul>
			</td>
			<td width="70%">
				<form id="editForm" method="post">
				<input type="hidden" name="goodsTypeId" id="editGoodsTypeId"/>
				<input type="hidden" name="pid" id="editPid"/>
				<table cellpadding="5" style="width:70%; font-size: 12px;">
					<tr>
						<td width="35%" align="right">分类名称：</td>
						<td width="65%" align="left"><input type="text" name="name" id="editName" style="width: 80%"/>&nbsp;&nbsp;<font color='red'>*</font></td>					
					</tr>
					<tr>
						<td align="right">分类描述：</td>
						<td align="left"><textarea name="note" id="editNote" style="width:80%" rows="5"></textarea>&nbsp;&nbsp;<font color='red'>*</font></td>					
					</tr>				
				</table>						
				<input  type="button" class="button-bar" value="编辑" onclick="doEdit();" ${f:op(ops,'商品分类管理','修改')}/>
				<input  type="button" class="button-bar" value="删除" onclick="doDel();" ${f:op(ops,'商品分类管理','删除')}/>
				</form>
				<div class="edit-line"></div>
				<br>
				<form id="addForm" method="post">
				<input type="hidden" name="pid" id="addPid"/>
				<table cellpadding="5" style="width:70%; font-size: 12px;">
					<tr>
						<td width="35%" align="right">父类名称：</td>
						<td width="65%" align="left"><input type="text" name="addPName" id="addPName" style="width: 80%" readonly="readonly"/></td>					
					</tr>
					<tr>
						<td width="35%" align="right">分类名称：</td>
						<td width="65%" align="left"><input type="text" name="name" id="addName" style="width: 80%"/>&nbsp;&nbsp;<font color='red'>*</font></td>					
					</tr>
					<tr>
						<td align="right">分类描述：</td>
						<td align="left"><textarea name="note" id="addNote" style="width:80%" rows="5"></textarea>&nbsp;&nbsp;<font color='red'>*</font></td>					
					</tr>				
				</table>
				<input  type="button" class="button-bar" value="新增" onclick="doAdd();" ${f:op(ops,'商品分类管理','新增')}/>	
				<input  type="button" class="button-bar" value="重置" onclick="refresh();" />							
				</form>
			</td>
		</tr>
	</table>
	
</body>
</html>
<script type="text/javascript">
<!--
var curNode;
//自动调用初始化
$(document).ready(function(){		
	$('#tree').tree({
		url:"${ctx}/goodsType!getTypeTree.action",
		onClick:function(node){			
			curNode=node;
			document.getElementById('editGoodsTypeId').value=curNode.id;
			document.getElementById('editName').value=curNode.text;
			document.getElementById('editNote').value=curNode.attributes.note;
			document.getElementById('editPid').value=curNode.attributes.pid;
			
			document.getElementById('addPid').value=curNode.id;
			document.getElementById('addPName').value=curNode.text;
			document.getElementById('addName').value='';
			document.getElementById('addNote').value='';
		}
	});
});
//添加子节点
function doAdd(){
	if ($("#addName").val() == ""){
		alert('分类名称不能为空！');
		return;
	}
	if ($("#addNote").val() == ""){
		alert('分类描述不能为空！');
		return;
	}
	var url="${ctx}/goodsType!add.action";
	$.post(url, $('#addForm').serialize() ,function callback(txt){   
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				refresh();		
			}else{
				alert('添加失败！');
			}
	});	
}
//编辑子节点
function doEdit(){
	if ($("#editName").val() == ""){
		alert('分类名称不能为空！');
		return;
	}
	if ($("#editNote").val() == ""){
		alert('分类描述不能为空！');
		return;
	}
	var url="${ctx}/goodsType!edit.action";
	$.post(url, $('#editForm').serialize() ,function callback(txt){   
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				refresh();		
			}else{
				alert('添加失败！');
			}
	});	
}

//删除节点
function doDel(){
	if(!curNode){
		alert('请先选择要删除的类型！');
		return;
	}
	if(confirm('确实要删除['+curNode.text+']吗？')){
		var url="${ctx}/goodsType!remove.action";
		$.post(url, "id="+curNode.id ,function callback(txt){   
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				refresh();	
			}else{
				alert('删除失败！');
			}
		});
	}
}

function refresh(){
	document.getElementById('editGoodsTypeId').value='';
	document.getElementById('editName').value='';
	document.getElementById('editNote').value='';
	document.getElementById('editPid').value='';
	
	document.getElementById('addPid').value='';
	document.getElementById('addPName').value='';
	document.getElementById('addName').value='';
	document.getElementById('addNote').value='';
	$('#tree').tree({
		url:"${ctx}/goodsType!getTypeTree.action"						
	});	
}

//-->
</script>
